home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / archivers / xpk / xpk_source / xpkmaster / xbuf.c < prev    next >
C/C++ Source or Header  |  1999-06-14  |  2KB  |  68 lines

  1. #ifndef XPKMASTER_XBUF_C
  2. #define XPKMASTER_XBUF_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        xbuf.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: xbuf.c 1.2 (09.01.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Xpk buffer handling
  12.  
  13.  1.0   09.10.96 : first real version
  14.  1.1   31.02.97 : now free's password buffer
  15.  1.2   09.09.98 : added XPK_ALLINONE
  16. */
  17.  
  18. #include <proto/exec.h>
  19. #include <exec/memory.h>
  20. #include <exec/libraries.h>
  21. #include <dos/dos.h>
  22. #include "xpkmaster.h"
  23.  
  24. /************************* alloc and init xbuf ***************************/
  25.  
  26. XPK_ALLINONE struct XpkBuffer *initxbuf(void)
  27. {
  28.   struct XpkBuffer *xbuf;
  29.  
  30.   if(!(xbuf = (struct XpkBuffer *) AllocMem(sizeof(struct XpkBuffer),
  31.   MEMF_CLEAR)))
  32.     return 0;
  33.   /* Save the original task priority in case we change it during an
  34.      operation */
  35.  
  36.   xbuf->xb_Priority = FindTask(0L)->tc_Node.ln_Pri;
  37.  
  38.   xbuf->xb_InLen = 0xFFFFFFFF;
  39.  
  40.   return xbuf;
  41. }
  42.  
  43. /***************************** free bufs *******************************/
  44. XPK_ALLINONE LONG freebufs(struct XpkBuffer *xbuf)
  45. {                /* Free an XpkBuffer */
  46.   LONG error = xbuf->xb_Result;
  47.  
  48.   if(xbuf->xb_xfd)
  49.   {
  50.     struct xfdMasterBase *xfdMasterBase = (struct xfdMasterBase *) xbuf->xb_SubBase;
  51.     xfdFreeObject(xbuf->xb_xfd);
  52.   }
  53.  
  54.   closesub(xbuf);            /* Free any open sub-library */
  55.   freeseek(xbuf);
  56.  
  57.   if(xbuf->xb_Flags & XMF_OWNTASKPRI)
  58.     SetTaskPri(FindTask (NULL), xbuf->xb_Priority);
  59.   if(xbuf->xb_Flags & XMF_OWNPASSWORD)
  60.     FreeMem(xbuf->xb_Password, xbuf->xb_PasswordSize);
  61.  
  62.   FreeMem(xbuf, sizeof(struct XpkBuffer));
  63.                 /* Finally, free the handle itself */
  64.   return error;
  65. }
  66.  
  67. #endif /* XPKMASTER_XBUF_C */
  68.